package gestion.camping.dao.impl;

import gestion.camping.dao.GenericDAO;
import gestion.camping.dto.Badge;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * Permet la lecture, la modification, l'ajout ou la suppresion en base des enregistrement de la table Type location
 * 
 * @author Gombert Damien
 * @author Foucras Melanie
 * @author Germa Romain
 * 
 * @version 1.0
 */
public class BadgeDao extends GenericDAO<Badge>{

	public BadgeDao(Connection conn) {
		super(conn);
	}

	
	@Override
	public Badge create(Badge obj) {
		return obj;
	}

	@Override
	public boolean delete(Badge obj) {
		return false;
	}

	@Override
	public Badge update(Badge obj) {	
		return obj;
	}

	@Override
	public Badge find(int id) {
		Badge dto = new Badge();
		
		try {
			
			Statement smt = connect.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
			
			String rqt = "SELECT * FROM BADGE B WHERE B.BADGE_NUM="+ id+" ORDER BY badge_num";
			
			//Execution de la requ�te
			ResultSet res = smt.executeQuery(rqt);		
			
			// si il y a des r�sultat, on se positionne sur le premier enregistrement
			if(res.first()){
				// Et on initialise le dto
				dto.setId(id);
				dto.setDroit(res.getString("BADGE_DROIT"));
				dto.setPris(res.getBoolean("BADGE_PRIS"));				
			}
			
			//On ferme la transaction
			smt.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return dto;
	}
}
